package csharp.cauth;

import java.util.List;

import org.bukkit.util.config.ConfigurationNode;

/**
 * @author Ярослав (CSharp) For easy configuration get.
 */
public class PluginConfig
{
	/**
	 * Booleans.
	 */
	public static Boolean usePermissions = false;
	public static Boolean useMySQL = false;
	public static Boolean rememberOperators = false;
	public static Boolean rememberUsePermissions = false;
	public static Boolean kickSameNicks = true;

	/**
	 * Integers.
	 */
	public static Integer kickPlayerAfter = 60;
	public static Integer accountsPerIP = 1;
	public static Integer wrongPasswordEnterCount = 5;

	/**
	 * Strings.
	 */
	public static String mysqlHost = "127.0.0.1";
	public static String mysqlDB = "cauth";
	public static String mysqlUser = "root";
	public static String mysqlPassword = "root";
	public static String language = "en";

	/**
	 * Array lists.
	 */
	public static List<Object> rememberGroups;

	public static void extractVariables()
	{
		ConfigurationNode general = CAuth.configuration.getNode("general");

		if (general != null)
		{
			usePermissions = general.getBoolean("usePermissions", false);
			useMySQL = general.getBoolean("useMySQL", false);
			kickSameNicks = general.getBoolean("kickSameNicks", true);
			language = general.getString("language", "en");
		}

		ConfigurationNode players = CAuth.configuration.getNode("players");

		if (players != null)
		{
			kickPlayerAfter = players.getInt("kickPlayerAfter", 60);
			accountsPerIP = players.getInt("accountsPerIP", 1);
			rememberOperators = players.getBoolean(
					"remember.rememberOperators", false);
			rememberUsePermissions = players.getBoolean(
					"remember.usePermissions", false);
			rememberGroups = players.getList("remember.groups");
			wrongPasswordEnterCount = players.getInt("wrongPasswordEnterCount",
					5);
		}

		ConfigurationNode mysql = CAuth.configuration.getNode("mysql");

		if (mysql != null)
		{
			mysqlHost = mysql.getString("host", "127.0.0.1");
			mysqlDB = mysql.getString("db", "cauth");
			mysqlUser = mysql.getString("user", "root");
			mysqlPassword = mysql.getString("password", "root");
		}
	}
}
